package com.wngbms.websocket.entity;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

public class UserDelay implements Delayed {

    private String userId;
    private long start;
    private long time;

    @Override
    public long getDelay(TimeUnit unit) {
        return unit.convert((start + time)
                - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    }

    @Override
    public int compareTo(Delayed o) {
        UserDelay userDelay = (UserDelay) o;
        return (int) (this.getDelay(TimeUnit.MILLISECONDS)
                - userDelay.getDelay(TimeUnit.MILLISECONDS));
    }

    @Override
    public String toString() {
        return "UserDelay{" +
                "userId='" + userId + '\'' +
                ", start=" + start +
                ", time=" + time +
                '}';
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public long getStart() {
        return start;
    }

    public void setStart(long start) {
        this.start = start;
    }

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }
}
